package cacco.jp.mld.panel.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cacco.jp.mld.panel.dao.UserDao;
import cacco.jp.mld.panel.entity.UserEntity;

@Service
public class UserService {

	@Autowired
	UserDao userDao;

	public List<UserEntity> getAll() {
		return userDao.getAll();
	}

	public UserEntity getUserByName(UserEntity userName) {
		return userDao.findByUsername(userName);
	}

	public UserEntity getUserByUserName(String userName) {
		return userDao.findByUsername(userName);
	}

	public int addUser(UserEntity user) {
		return userDao.add(user);
	}

	public void updateUser(UserEntity user) {
		userDao.update(user);
	}

	public void deleteUser(Integer id) {
		userDao.delete(id);
	}

	public List<UserEntity> getAlByPage(int pageSize, int page, String sidx,
			String sord) {
		return userDao.getAlByPage(pageSize, page, sidx, sord);
	}

	public boolean isExistUser(int id) {
		UserEntity entity = null;
		entity = userDao.findById(id);
		if (entity != null) {
			return true;
		}
		return false;
	}

	public int getTotalRecords() {
		return userDao.getTotalRecords();
	}

}
